<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>user列表</title>
<%@include file="../common/include.jsp"%>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-lg-10">
				<br />
				<div class="panel panel-default">
					<div class="panel-body">
						<button type="button" onclick="preSave()" class="btn btn-default">添加</button>
						<button type="button" onclick="build()" class="btn btn-default">随机生成10条数据</button>
					</div>
					<table class="table table-bordered">
						<thead>
							<tr>
								<th>id</th>
								<th>username</th>
								<th>password</th>
								<th>enabled</th>
								<th>createDate</th>
								<th>age</th>
								<th>name</th>
								<th>操 作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="item" items="${data}">
								<tr>
									<td>${ item.id }</td>
									<td>${ item.username }</td>
									<td>${ item.password }</td>
									<td>${ item.enabled }</td>
									<td>${ item.createDate }</td>
									<td>${ item.age }</td>
									<td>${ item.name }</td>
									<td><a href="javascript:void(0);" onclick="preSave('${item.id}')" title="编辑"> <i class="glyphicon glyphicon-edit"></i>
									</a>&nbsp;<a href="javascript:void(0);" onclick="del('${item.id}')" title="删除"> <i class="glyphicon glyphicon-remove"></i>
									</a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script>
		function preSave(id) {
			if (id == undefined || id == null || id == '') {
				window.location.href = '${ctx}/demo/user/preSave';
			} else {
				window.location.href = '${ctx}/demo/user/preSave?id=' + id;
			}
		}

		function build() {
			window.location.href = '${ctx}/demo/user/build';
		}

		function del(id) {
			$.ajax({
				type : 'POST',
				url : '${ctx}/demo/user/delete',
				data : {
					id : id
				},
				dataType : 'json',
				success : function(data) {
					//alert(data.msg);
					if (data.success) {
						setTimeout('toIndex("demo/user/")', 100);
					}
				},
				error : function() {
					alert("出错了,请重试!");
				}
			});
		}
	</script>
</body>
</html>
